
#include "NewDuplicate.h"
#include "Common/EventDefine.h"
#include "Duplicate/DuplicateMgr.h"
#include "Character/Part.h"
#include "Character/monster/MonsterMgr.h"
#include "Character/monster/MonsterRefCfg.h"

NewDuplicate::NewDuplicate()
{
	m_byType = (int8_t)EDuplicateType::EDuplicateType_New;
}

NewDuplicate::~NewDuplicate()
{

}

bool NewDuplicate::Init(uint32_t nDuplicateID, uint32_t nSceneID, IBrushMonster *pBrush)
{
	return Duplicate::Init(nDuplicateID, nSceneID, pBrush);
}

//
void NewDuplicate::UnInit()
{
	Duplicate::UnInit();
}

void NewDuplicate::OnTimerUpdate(uint32_t nTimerID)
{
	switch (nTimerID)
	{
	case ETimer_Flop:
		{
			//翻牌结束
			OnCommon_FlopStateEnd();
		}
		break;
	case ETimer_Clean:
		{
			OnCommon_CleanStateEnd();
		}
		break;
	case ETimer_Destory:
		{
			LogDebugFmtPrint("[logic] NewDuplicate destory .... duplicateid:%u , sceneid:%u, mapid:%u ", m_nDuplicateID, m_nSceneID, m_nMapID);
			OnCommon_DestoryStateEnd();
		}
		break;
	}
}

void NewDuplicate::OnExecuteEvent(uint16_t nEventID, uint32_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen)
{
	switch (nEventID)
	{
	case EVENT_CREATURE_DEAD:
		{
		}
		break;
	case EVENT_ENTER_SCENE:
		{
		}
		break;
	case EVENT_DISCONNECT:
		{
		}
		break;
	}
}
//生物进入场景
void NewDuplicate::OnCreatureEnter(Creature *pCreature)
{
	/*if (nullptr == pCreature)
	{
		return;
	}
	if (CREATURE_PLAYER == pCreature->CreatureKind())
	{
		//订阅角色刷怪事件
		if (!g_GetEvent()->Subscribe(this, EVENT_CREATURE_DEAD, pCreature->GetCid(), CREATURE_MONSTER, "NewDuplicate"))
		{
			LogErrFmtPrint("[logic] NewDuplicate::EnterDuplicate....Subscribe monster dead event failed....");
		}

		//订阅角色掉线事件
		if (!g_GetEvent()->Subscribe(this, EVENT_DISCONNECT, pCreature->GetCid(), CREATURE_PLAYER, "NewDuplicate"))
		{
			LogErrFmtPrint("[logic] NewDuplicate::EnterDuplicate....Subscribe player disconnect event  failed....");
		}

		//订阅角色死亡事件
		if (!g_GetEvent()->Subscribe(this, EVENT_CREATURE_DEAD, pCreature->GetCid(), CREATURE_PLAYER, "NewDuplicate"))
		{
			LogErrFmtPrint("[logic] NewDuplicate::EnterDuplicate....Subscribe player dead event  failed....");
		}

		LogDebugFmtPrint("[logic] NewDuplicate::EnterDuplicate success...cid:%u ,duplicateid:%u", pCreature->GetCid(), m_nDuplicateID);
	}*/
}

//是否能进入
bool NewDuplicate::OnCanEnter(Creature *pCreature)
{
	//新手副本准备状态才能进入
	if (GetDuplicateState() == (int8_t)EDuplicateState::EDuplicateState_Ready)
	{
		if (m_setPlayer.size() < 1) //新手副本只允许一个人
		{
			return true;
		}
	}

	return false;
}

//进入区域
bool NewDuplicate::OnEnterArea(uint32_t nAreaID)
{
	nAreaID = nAreaID;
	return true;
}

//复活
void NewDuplicate::OnRelive(Player *pPlayer, int8_t byType)
{
	pPlayer = pPlayer;
	byType = byType;
}

void NewDuplicate::OnReady_State()
{
	
}

void NewDuplicate::OnBegin_State()
{
	OnCommon_DupBeginState();
}

void NewDuplicate::OnFinish_State()
{
	OnCommon_DupFinishState();
}

void NewDuplicate::OnFlop_State()
{
	//设置抽奖时间 20s
	LogDebugFmtPrint("[logic] NewDuplicate::OnDuplicateState_Flop....duplicateid:%u , sceneid:%u ", m_nDuplicateID, m_nSceneID);
	OnCommon_DupFlopState();
}

void NewDuplicate::OnClean_State()
{
	//删除抽奖定时器
	LogDebugFmtPrint("[logic] NewDuplicate::OnClean_State....duplicateid:%u , sceneid:%u ", m_nDuplicateID, m_nSceneID);
	OnCommon_DupCleanState();
}

void NewDuplicate::OnDestory_State()
{
	OnCommon_DupDestoryState();
}
